﻿<Window x:Class="WSManager.Wpf.ArticleEditor.ArticleEditor"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:loc="clr-namespace:WSManager.Wpf.ArticleEditor"
        Title="NewArticle" Height="500" Width="700" x:Name="window">
    <Window.DataContext>
        <loc:EditorViewModel x:Name="viewModel"></loc:EditorViewModel>
    </Window.DataContext>
    <Grid>
        <Grid Margin="5">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0">
                <TextBox Name="name" Text="{Binding Name, Mode=TwoWay}" MinWidth="100" FontFamily="Cambria" FontSize="20" FontWeight="Bold" Margin="5" ToolTip="Name" Padding="5"></TextBox>
                <TextBox Text="{Binding Description, Mode=TwoWay}" SpellCheck.IsEnabled="True" AcceptsReturn="True" TextWrapping="Wrap" ToolTip="Description" Margin="5" MinLines="5" Padding="5" />
                <Grid x:Name="categories">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="Horizontal" Grid.Row="0">
                        <TextBlock Text="Categories: "></TextBlock>
                        <TextBlock Text="{Binding SelectedCategoriesString}"/>
                        <Button Command="{Binding ToggleCategoriesSelectingCommand}" Padding="5,1">
                            <Button.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding CategoriesSelecting}" Value="True">
                                            <Setter Property="Button.Content" Value="↑" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding CategoriesSelecting}" Value="False">
                                            <Setter Property="Button.Content" Value="↓" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                    </StackPanel>
                    <Grid Grid.Row="1" Width="Auto" MinHeight="20" MinWidth="100" HorizontalAlignment="Left">
                        <Grid.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding CategoriesSelecting}" Value="True">
                                        <Setter Property="Grid.Visibility" Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding CategoriesSelecting}" Value="False">
                                        <Setter Property="Grid.Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                    </Style.Triggers></Style></Grid.Style>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TreeView ItemsSource="{Binding Categories}" ScrollViewer.CanContentScroll="True" x:Name="categoryTree" Grid.Row="1" Margin="10,1">
                            <TreeView.ItemContainerStyle>
                                <Style>
                                    <Setter Property="TreeViewItem.IsExpanded" Value="True"/>
                                </Style>
                            </TreeView.ItemContainerStyle>

                            <TreeView.ItemTemplate>
                                <HierarchicalDataTemplate ItemsSource="{Binding Subcategories}">
                                    <TextBlock TextWrapping="WrapWithOverflow">
                                            <CheckBox IsChecked="{Binding Checked, Mode=TwoWay}" ></CheckBox>
                                            <TextBlock Text="{Binding Name}" ToolTip="{Binding Description}" FontSize="17" FontWeight="Bold" />
                                            <TextBlock FontSize="12" FontStyle="Italic">('<TextBlock Text="{Binding Description}"/>')</TextBlock>
                                        </TextBlock>
                                    </HierarchicalDataTemplate>
                            </TreeView.ItemTemplate>
                        </TreeView>
                    </Grid>
                </Grid>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBox Margin="5,0" Padding="5" Grid.Column="0" Text="{Binding FileName, Mode=TwoWay}"/>
                    <Button Content="Browse" HorizontalAlignment="Right" Name="button1" Width="90" Style="{StaticResource bigButton}" Grid.Column="1" Command="{Binding FileDialog}" />
                    <Button Content="Load" Style="{StaticResource bigButton}" Width="90" Grid.Column="2" Command="{Binding FileLoad}" ></Button>
                </Grid>
            </StackPanel>
            <Grid Grid.Row="1">
                <ScrollViewer>
                    <ContentPresenter Content="{Binding XamlContent}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" />
                </ScrollViewer>
            </Grid>
            <StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
                <Button Command="{Binding EditMeta}" Content="Edit metadata">
                    <Button.Style>
                        <Style BasedOn="{StaticResource bigButton}" TargetType="Button">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=MetadataValid}" Value="False">
                                    <Setter Property="Background" Value="Red" />
                                    <Setter Property="ToolTip" Value="Some errors in metadata" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                </Button>
                <Button Command="{Binding Save}" CommandParameter="{Binding ElementName=window}" Content="Save" Style="{StaticResource bigButton}"></Button>
            </StackPanel>
        </Grid>
        <Grid Visibility="{Binding Loading, Converter={StaticResource boolToVisibility}}">
            <Rectangle Fill="Black" Opacity="0.2"></Rectangle>
            <TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Grid>
    </Grid>
</Window>